package user.controller;

import core.controller.BaseController;
import core.domain.ListDataInfo;
import core.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import user.domain.exam.dto.ExamQueryDTO;
import user.domain.exam.dto.ExamRankDTO;
import user.service.IExamService;

@RestController
@Slf4j
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;
    @RequestMapping("/semiLogin/list")
    public ListDataInfo list(ExamQueryDTO query) {
        log.info("C -> ExamController -> list: {}", query);
        return toListDataInfo(examService.list(query));
    }


    @GetMapping("/semiLogin/redis/list")
    public ListDataInfo redisList(ExamQueryDTO query) {
        log.info("C -> ExamController -> redisList: {}", query);
        return examService.redisList(query);
    }

    @GetMapping("/getFirstQuestion")
    public Result<String> getFirstQuestion(Long examId){
        log.info("C -> ExamController -> getFirstQuestion: {}", examId);
        return Result.success(examService.getFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public Result<String> preQuestion(Long examId, Long questionId){
        log.info("C -> ExamController -> preQuestion: {}, {}", examId, questionId);
        return Result.success(examService.preQuestion(examId, questionId));
    }

    @GetMapping("/nextQuestion")
    public Result<String> nextQuestion(Long examId, Long questionId){
        log.info("C -> ExamController -> nextQuestion: {}, {}", examId, questionId);
        return Result.success(examService.nextQuestion(examId, questionId));
    }

    @GetMapping("/rank/list")
    public ListDataInfo rankList(ExamRankDTO examRankDTO){
        return examService.rankList(examRankDTO);
    }
}
